package org.ls.petclinic.web;

import org.ls.petclinic.dao.VetDao;
import org.ls.petclinic.dao.impl.VetDaoImpl;
import org.ls.petclinic.pojo.Vet;
import org.ls.petclinic.untils.JdbcUtils;
import org.ls.petclinic.untils.ResultJson;
import org.ls.petclinic.untils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description
 * @Author 浪矢先生
 * @Create 2022-06-10 10:26
 */
@WebServlet(urlPatterns = "/addVet")
public class AddVetServlet extends BaseServlet{
    private VetDao vetDao = new VetDaoImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Vet vet = WebUtils.copyParamToBean(req.getParameterMap(), new Vet());
        int i = vetDao.addVet(vet);
        JdbcUtils.commitAndClose();
        //页面重定向
        resp.sendRedirect(req.getContextPath() + "/jsp/getVet.jsp");
    }
}
